﻿<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <!-- this template replaces the newlines in the text parameter with <br/, and outputs the < character un-escaped instead of &lt;
     and outputs the parameter -->
  <xsl:template name="break">
    <xsl:param name="text"/>
    <xsl:choose>
      <xsl:when test="contains($text, '&lt;')">
        <xsl:call-template name="break">
          <xsl:with-param name="text" select="substring-before($text,'&lt;')"/>
        </xsl:call-template>
        <![CDATA[<]]>
        <xsl:call-template name="break">
          <xsl:with-param name="text" select="substring-after($text,'&lt;')"/>
        </xsl:call-template>
      </xsl:when>

      <xsl:when test="contains($text, '&gt;')">
        <xsl:call-template name="break">
          <xsl:with-param name="text" select="substring-before($text,'&gt;')"/>
        </xsl:call-template>
        <xsl:text disable-output-escaping="yes">&gt;</xsl:text>
        <xsl:call-template name="break">
          <xsl:with-param name="text" select="substring-after($text,'&gt;')"/>
        </xsl:call-template>
      </xsl:when>

      <xsl:when test="contains($text, '&#13;&#10;')">
        <xsl:value-of select="substring-before($text,'&#13;&#10;')"/>
        <xsl:text disable-output-escaping="yes"><![CDATA[<br/>]]></xsl:text>
        <xsl:call-template name="break">
          <xsl:with-param name="text" select="substring-after($text,'&#13;&#10;')"/>
        </xsl:call-template>
      </xsl:when>

      <xsl:otherwise>
        <xsl:value-of select="$text"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- handle IMDBrating field - set stars 1 to 10 -->
  <xsl:template name="starIMDB">
    <xsl:param name="numIMDB" select="0"/>
    <xsl:param name="LoopNum" select="0"/>
    <xsl:param name="imageRoot" select="''"/>
    <xsl:choose>
      <xsl:when test="$LoopNum&lt;'10'">
        <xsl:choose>
          <xsl:when test="$numIMDB&lt;'0' or $numIMDB = '0'">
            <img src="{$imageRoot}images/Stars/Emptystar.gif" width="15" height="15" border="0"/>
            <xsl:call-template name="starIMDB">
              <xsl:with-param name="numIMDB" select="$numIMDB - 1"/>
              <xsl:with-param name="LoopNum" select="$LoopNum + 1"/>
              <xsl:with-param name="imageRoot" select="$imageRoot"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:when test="$numIMDB&lt;='.1' and $numIMDB > '0'">
            <img src="{$imageRoot}images/Stars/Redstar.1.gif" width="15" height="15" border="0"/>
            <xsl:call-template name="starIMDB">
              <xsl:with-param name="numIMDB" select="$numIMDB - 1"/>
              <xsl:with-param name="LoopNum" select="$LoopNum + 1"/>
              <xsl:with-param name="imageRoot" select="$imageRoot"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:when test="$numIMDB&lt;='.2' and $numIMDB > '.1'">
            <img src="{$imageRoot}images/Stars/Redstar.2.gif" width="15" height="15" border="0"/>
            <xsl:call-template name="starIMDB">
              <xsl:with-param name="numIMDB" select="$numIMDB - 1"/>
              <xsl:with-param name="LoopNum" select="$LoopNum + 1"/>
              <xsl:with-param name="imageRoot" select="$imageRoot"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:when test="$numIMDB&lt;='.3' and $numIMDB > '.2'">
            <img src="{$imageRoot}images/Stars/Redstar.3.gif" width="15" height="15" border="0"/>
            <xsl:call-template name="starIMDB">
              <xsl:with-param name="numIMDB" select="$numIMDB - 1"/>
              <xsl:with-param name="LoopNum" select="$LoopNum + 1"/>
              <xsl:with-param name="imageRoot" select="$imageRoot"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:when test="$numIMDB&lt;='.4' and $numIMDB > '.3'">
            <img src="{$imageRoot}images/Stars/Redstar.4.gif" width="15" height="15" border="0"/>
            <xsl:call-template name="starIMDB">
              <xsl:with-param name="numIMDB" select="$numIMDB - 1"/>
              <xsl:with-param name="LoopNum" select="$LoopNum + 1"/>
              <xsl:with-param name="imageRoot" select="$imageRoot"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:when test="$numIMDB&lt;='.5' and $numIMDB > '.4'">
            <img src="{$imageRoot}images/Stars/Redstar.5.gif" width="15" height="15" border="0"/>
            <xsl:call-template name="starIMDB">
              <xsl:with-param name="numIMDB" select="$numIMDB - 1"/>
              <xsl:with-param name="LoopNum" select="$LoopNum + 1"/>
              <xsl:with-param name="imageRoot" select="$imageRoot"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:when test="$numIMDB&lt;='.6' and $numIMDB > '.5'">
            <img src="{$imageRoot}images/Stars/Redstar.6.gif" width="15" height="15" border="0"/>
            <xsl:call-template name="starIMDB">
              <xsl:with-param name="numIMDB" select="$numIMDB - 1"/>
              <xsl:with-param name="LoopNum" select="$LoopNum + 1"/>
              <xsl:with-param name="imageRoot" select="$imageRoot"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:when test="$numIMDB&lt;='.7' and $numIMDB > '.6'">
            <img src="{$imageRoot}images/Stars/Redstar.7.gif" width="15" height="15" border="0"/>
            <xsl:call-template name="starIMDB">
              <xsl:with-param name="numIMDB" select="$numIMDB - 1"/>
              <xsl:with-param name="LoopNum" select="$LoopNum + 1"/>
              <xsl:with-param name="imageRoot" select="$imageRoot"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:when test="$numIMDB&lt;='.8' and $numIMDB > '.7'">
            <img src="{$imageRoot}images/Stars/Redstar.8.gif" width="15" height="15" border="0"/>
            <xsl:call-template name="starIMDB">
              <xsl:with-param name="numIMDB" select="$numIMDB - 1"/>
              <xsl:with-param name="LoopNum" select="$LoopNum + 1"/>
              <xsl:with-param name="imageRoot" select="$imageRoot"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:when test="$numIMDB&lt;='.9' and $numIMDB > '.8'">
            <img src="{$imageRoot}images/Stars/Redstar.9.gif" width="15" height="15" border="0"/>
            <xsl:call-template name="starIMDB">
              <xsl:with-param name="numIMDB" select="$numIMDB - 1"/>
              <xsl:with-param name="LoopNum" select="$LoopNum + 1"/>
              <xsl:with-param name="imageRoot" select="$imageRoot"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:when test="$numIMDB>=1">
            <img src="{$imageRoot}images/Stars/Redstar.gif" width="15" height="15" border="0"/>
            <xsl:call-template name="starIMDB">
              <xsl:with-param name="numIMDB" select="$numIMDB - 1"/>
              <xsl:with-param name="LoopNum" select="$LoopNum + 1"/>
              <xsl:with-param name="imageRoot" select="$imageRoot"/>
            </xsl:call-template>
          </xsl:when>
        </xsl:choose>
      </xsl:when>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
